package com.lyf.viewapp.picture.show.loader;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.lyf.viewapp.picture.show.ImageUrlConfig;
import com.previewlibrary.loader.IZoomMediaLoader;
import com.previewlibrary.loader.MySimpleTarget;

/**
 * Created by lyf on 2018/5/24 09:38
 *
 * @author lyf
 * desc：图片加载
 */
public class ImageDetailShowLoader implements IZoomMediaLoader{
    @Override
    public void displayImage(@NonNull Fragment context, @NonNull String path, @NonNull final MySimpleTarget<Bitmap> simpleTarget) {
       Glide.with(context)
               .asBitmap()
               .apply(ImageUrlConfig.options)
               .load(path)
               .into(new SimpleTarget<Bitmap>() {
                   @Override
                   public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                       simpleTarget.onResourceReady(resource);
                   }

                   @Override
                   public void onLoadStarted(@Nullable Drawable placeholder) {
                       super.onLoadStarted(placeholder);
                       simpleTarget.onLoadStarted();
                   }

                   @Override
                   public void onLoadFailed(@Nullable Drawable errorDrawable) {
                       super.onLoadFailed(errorDrawable);
                       simpleTarget.onLoadFailed(errorDrawable);
                   }
               });
    }

    @Override
    public void onStop(@NonNull Fragment context) {
        Glide.with(context).onStop();
    }

    @Override
    public void clearMemory(@NonNull Context c) {
        Glide.get(c).clearMemory();
    }
}
